package com.css.apps.base.role.action;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.css.core.configuration.Environment;
import com.css.db.query.QueryCache;
import com.css.util.Ajax;
import com.css.util.Messages;
import com.css.util.StringHelper;
import com.css.webbase.webwork.action.AdminAction;
import com.opensymphony.xwork.Action;

/**
 * <p>
 * 获得组织机构-用户树
 * </p>
 * 
 */
@SuppressWarnings("serial")
public class GetOrgUserTreeRole extends AdminAction {
	private static Log log = LogFactory.getLog(GetOrgUserTreeRole.class);
	private String roleId;

	@SuppressWarnings("unchecked")
	@Override
	protected String adminGo() {
		try {
			if (StringHelper.isEmpty(roleId)) {
				result = Ajax.JSONResult(Environment.RESULT_CODE_ERROR, Messages.getString("systemMsg.fieldEmpty"));
				return ERROR;
			}
			List<String> userIdList = new QueryCache("select distinct a.userId from SUserRole a where a.roleId = :roleId")
					.setParameter("roleId", roleId).list();
			result = RoleItem.getAllOrgUserTree(StringHelper.listToStr(userIdList)).toString();
			return SUCCESS;
		} catch (Exception ex) {
			result = Ajax.JSONResult(Environment.RESULT_CODE_ERROR, Messages.getString("systemMsg.exception"));
			log.error(ex.getMessage(), ex);
			return Action.ERROR;
		}
	}
	
	public String getRoleId() {
		return roleId;
	}

	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}

}
